﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace B2B.Models
{
    public class SP_LayDonHang
    {
        int maDH;

        public int MaDH
        {
            get { return maDH; }
            set { maDH = value; }
        }
        string tenSP;

        public string TenSP
        {
            get { return tenSP; }
            set { tenSP = value; }
        }
        private string email;

        public string Email
        {
            get { return email; }
            set { email = value; }
        }
        int slDat;

        public int SlDat
        {
            get { return slDat; }
            set { slDat = value; }
        }
        double gia;

        public double Gia
        {
            get { return gia; }
            set { gia = value; }
        }
        double tongTien;

        public double TongTien
        {
            get { return tongTien; }
            set { tongTien = value; }
        }
        string baoGia;

        public string BaoGia
        {
            get { return baoGia; }
            set { baoGia = value; }
        }

        private string hinhAnh;

        public string HinhAnh
        {
            get { return hinhAnh; }
            set { hinhAnh = value; }
        }

        public SP_LayDonHang layDonDatHang(int maDH)
        {
            SP_LayDonHang sp_LayDonHang = new SP_LayDonHang();
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_LAYDONDATHANG", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@MADH", maDH);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                sp_LayDonHang.MaDH = reader.GetInt32(0);
                sp_LayDonHang.TenSP = reader.GetString(1);
                sp_LayDonHang.Email = reader.GetString(2);
                sp_LayDonHang.SlDat = reader.GetInt32(3);
                sp_LayDonHang.Gia = double.Parse(reader.GetDecimal(4).ToString());
                sp_LayDonHang.tongTien = double.Parse(reader.GetDecimal(5).ToString());
                sp_LayDonHang.BaoGia = reader.GetString(6);
                sp_LayDonHang.HinhAnh = reader.GetString(7);
            }
            return sp_LayDonHang;
        }
    }
}